/*
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                   O\  =  /O
 *                ____/`- -'\____
 *              .'  \\|     |//  `.
 *             /  \\|||  :  |||//  \
 *            /  _||||| -:- |||||-  \
 *            |   | \\\  -  /// |   |
 *            | \_|  ''\- -/''  |   |
 *            \  .-\__  `-`  ___/-. /
 *          ___`. .'  /- . -\  `. . __
 *       ."" '<  `.___\_<|>_/___.'  >'"".
 *      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *      \  \ `-.   \_ __\ /__ _/   .-` /  /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=- -='
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *           佛祖保佑       永无BUG
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 */

package com.softeem.starwars.entity;

import com.softeem.starwars.panel.GamePanel;
import com.softeem.starwars.utils.ImageLoader;
import com.softeem.starwars.utils.Settings;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @Author mrchai 2020/4/8 19:29
 */
public class Bullet extends Sprite implements Runnable{

    private int speed = 5;

    public Bullet(int x, int y) {
        super();
        setX(x);
        setY(y);
    }

    @Override
    public void init() {
        BufferedImage img = ImageLoader.load("bullet/bullet1.png");
        setImg(img);
        setWidth(img.getWidth());
        setHeight(img.getHeight());
    }

    @Override
    public void draw(Graphics g) {
        g.drawImage(getImg(),getX(),getY(),getWidth(),getHeight(),null);
    }

    @Override
    public void destroy() {
        GamePanel.bullets.remove(this);
    }

    @Override
    public void run() {
        while(getX() < Settings.WIDTH){
            setX(getX() + speed);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        destroy();
    }
}
